//仓库系统数据存储

class ItemData
{
    itemId : number;
    itemNum : number;
    itemName : string;
    itemSkin : string;
    itemScore : number;
    itemTime : number;
    itemRate : number;
    itemMreward : number;
    constructor(id:number, num:number, name:string, skin:string, score:number, time:number, rate:number, mreward:number)
    {
        this.itemId = id;
        this.itemNum = num;
        this.itemName = name;
        this.itemSkin = skin;
        this.itemScore = score;
        this.itemTime = time;
        this.itemRate = rate;
        this.itemMreward = mreward;
    }
}

class WareHouse {
    private data_list : Array<ItemData>;  //总列表
    private ur_list : Array<ItemData>;    //普通种子列表
    private sr_list : Array<ItemData>;    //稀有种子列表
    private ssr_list : Array<ItemData>;   //史诗种子列表
    private item_list : Array<ItemData>;  //道具列表

    Init()
    {
        //清空所有表
        this.data_list = [];
        this.ur_list = [];
        this.sr_list = [];
        this.ssr_list = [];
        this.item_list = [];

        //根据json配置初始化所有道具
        for (let key in Cfg.ItemCfg) {
            let item = Cfg.ItemCfg[key]
            let newItem : ItemData = new ItemData(item.id, 0, item.name, item.skin, item.score, item.time, item.rate, item.mreward);
            this.data_list.push(newItem);
        }

        //细分为四个列表
        this.data_list.forEach(item =>{
            switch (item.itemRate)
            {   
                case 0 :
                    this.item_list.push(item);
                    break;
                case 1 :
                    this.ur_list.push(item);
                    break;
                case 2 :
                    this.sr_list.push(item);
                    break;
                case 3 :
                    this.ssr_list.push(item);
                    break;
                default :
                    break;
            }
        });
    }

    //添加道具(以后再说，现在不用)
    AddItem(id : number, name : string, score : number, time : number, skin : string, rate : number, mreward : number)
    {
            let newItem : ItemData = new ItemData(id, 0, name, skin, score, time, rate, mreward);
            this.data_list.push(newItem);
    }

    //设置道具个数
    SetItemCount(id : number, count : number)
    {
        this.data_list.forEach(item => {
            if (id == item.itemId)
            {
                item.itemNum = count;
            }
        });
    }


    //改变道具个数
    ChangeItemCount(id : number, count : number)
    {
        this.data_list.forEach(item => {
            if (id == item.itemId)
            {
                item.itemNum = item.itemNum + count;
            }
        });
    }

    //获取UR种子列表
    GetUrSeedList() : Array<ItemData>
    {
        return this.ur_list;
    }

    //获取SR种子列表
    GetSrSeedList() : Array<ItemData>
    {
        return this.sr_list;
    }

    //获取SSR种子列表
    GetSsrSeedList() : Array<ItemData>
    {
        return this.ssr_list;
    }

    //获取道具列表
    GetItemList() : Array<ItemData>
    {
        return this.item_list;
    }
}

let WarehouseModel : WareHouse = new WareHouse();